<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>对象转换</title>
		<script type="text/javascript">
			var str = '{"name":"张三","age":"20"}';
			var obj = JSON.parse(str, fun);

			function fun(name, value) {
				console.log(name + ":" + value);
				return value;
			}
			console.log(obj);
			var jsonStr = JSON.stringify(obj);
//			console.log(jsonStr);
		</script>
	</head>

	<body>
		<h2>从 JSON 对象中创建 JavaScript 对象</h2>

		<p id="demo1"></p>

		<script>
			var obj = JSON.parse('{ "name":"runoob", "alexa":10000, "site":"www.runoob.com" }');
			document.getElementById("demo1").innerHTML = obj.name + "：" + obj.site;
		</script>

		<h2>将 JavaScript 数组转换为 JSON 对象</h2>

		<p id="demo2"></p>

		<script>
			var arr = ["Google", "Runoob", "Taobao", "Facebook"];
			var myJSON = JSON.stringify(arr);
			document.getElementById("demo2").innerHTML = myJSON;
		</script>
	</body>

</html>